﻿namespace Licens.Class
{
    using System;
    using System.Data;
    using System.Management;

    public static class SystemInfo
    {
        public static string[] GetArrayCharFromASCII()
        {
            string[] strArray = new string[0x1a];
            for (int i = 0x41; i <= 90; i++)
            {
                strArray[i - 0x41] = ((char) i).ToString();
            }
            return strArray;
        }
        public static string GetMaASCII
        {
            get { return "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; }
        }
        public static DataTable GetDataCharFromASCII()
        {
            return GetDataCharFromASCII(DateTime.Now.Day);
        }
        public static DataTable GetDataCharFromASCII(char kitubatdau)
        {
           
            string vs_ascii = GetMaASCII;            

            int vi_vitribd = vs_ascii.IndexOf(kitubatdau);
            
            return GetDataCharFromASCII(vi_vitribd);

        }
        public static DataTable GetDataCharFromASCII(int vitribatdau)
        {
            DataTable table = new DataTable();
            table.Columns.Add("so", typeof(int));
            table.Columns.Add("kitu");
            string vs_ascii = GetMaASCII;
            string vs_ma = vs_ascii + vs_ascii;

            for (int i = vitribatdau; i <=vitribatdau+ 9; i++)
            {
                object[] values = new object[] { i - vitribatdau, vs_ma.Substring(i, 1) };
                table.Rows.Add(values);
            }
            return table;
        }

        public static string GetHDDSerialNumber()
        {
            ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive");
            foreach (ManagementObject obj2 in searcher.Get())
            {
                try
                {
                    return obj2["SerialNumber"].ToString();
                }
                catch
                {
                    return obj2["Model"].ToString();
                }
            }
            return "";
        }

        public static string GetHDDSerialNumber(string drive)
        {
            if ((drive == "") || (drive == null))
            {
                drive = "C";
            }
            ManagementObject obj2 = new ManagementObject("Win32_LogicalDisk.DeviceID=\"" + drive + ":\"");
            obj2.Get();
            return obj2["VolumeSerialNumber"].ToString();
        }

        public static int GetIndexCharFromASCII(string c)
        {
            string[] arrayCharFromASCII = GetArrayCharFromASCII();
            for (int i = 0; i < arrayCharFromASCII.Length; i++)
            {
                if (arrayCharFromASCII[i] == c.ToString())
                {
                    return i;
                }
            }
            return -1;
        }
    }
}

